//会员管理——会员列表
var ttname = ""; //当前选项卡名字
var starttime = ""; //开始时间
var endtime = ""; //结束时间
var pagesize = 10;
var pageindex = 1;
var sortfild = ""; //排序的关键字
var sortway = ""; //排序：升序、降序
var current_user_id = getCookie("user_id"); //用户id
var current_user_encryptId = getCookie("user_encryptId"); //用户id
var palytypelist = "", themelist = "";//游玩类型，主题游
var ttname = "";
$(function () {

    // getAllfarmMertype();//农家乐商户类型
    // //获取景区商户类型
    // getAllSerMertype();

    //排序 
    $(".list_sort_tab").click(function () {
        sortfild = $(this).attr("value");
        if ($(this).find("i").hasClass("icon_downs")) {
            $(this).find("i").removeClass("icon_downs");
            $(this).find("i").addClass("icon_ups");
            sortway = "asc";
        } else {
            $(this).find("i").removeClass("icon_ups");
            $(this).find("i").addClass("icon_downs");
            sortway = "desc";
        }
        //必须要，否则排序则不能调用该方法  使用该句，当点击排序，就同时点击了 第一页的按钮，自动调用分页的效果，
        $("#first_button").click();
    });

    //悬浮显示 当宽度小于 文字宽度时，则鼠标移到该内容时，悬浮显示，将文字全部显示出来
    $(document).on("mouseover", ".show_tips", function () {
        if ($(this).width() > $(this).parent().width()) {
            layer.tips($(this).html(), $(this), {
                tips: [1, '#3595CC'],
                time: 0
            })
        }
    });
    $(document).on("mouseout", ".show_tips", function () {
        layer.closeAll('tips');
    });

    //评价图片显示
    $(document).on("click", ".show_img", function () {
        var allvalue = $(this).attr("src").split(",");
        var str = "";
        for (var i = 0; i < allvalue.length; i++) {
            if (str == "") {
                str = allvalue[i];
            } else {
                str += "," + allvalue[i];
            }
        }
        var url = str.split(",");
        var prompt = '<div class="swiper-container">';
        prompt += "<div class='swiper-wrapper jilu_swiper'>";
        for (var i = 0; i < url.length; i++) {
            prompt += "<div class=\"swiper-slide\"><img style='max-width:480px;max-height:300px;' onclick='enlargeCoatchAttachment(\"" + url + "\",\"" + url[i] + "\")' src='" + url[i] + "'></div>";
        }
        prompt += "</div>";
        if (url.length > 1) {
            /*导航按钮*/
            prompt += "<div class=\"swiper-button-prev prev_swiper\"></div><div class=\"swiper-button-next next_swiper\"></div>";
        }
        prompt += "</div>";
        /*分页器*/
        prompt += "<div class=\"swiper-pagination\"></div>";

        var cancel = "<div class=\"linepopup_div\"></div>";
        cancel += "<div class=\"d_btn\">";
        cancel += "<div class=\"linepopup_button\">";
        cancel += "<a href=\"javascript:mclose()\" class=\"sure_btn1\">取消</a>";
        cancel += "</div>";
        cancel += "</div>";


        var confirm = "";
        var html = "<div class='linepopup1'>" + prompt + "</div>" + cancel
            + confirm;
        ComOpenWin(1, "图片", "auto", 'auto', html, 1);

        var mySwiper = new Swiper('.swiper-container', {
            pagination: {
                el: '.swiper-pagination',
                type: 'fraction'
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev'
            }
        })
    });


    /*基本信息修改*/
    $(".client_int").bind('input propertychange', function () {
        $(".client_tool").css("display", "none");
        $(this).siblings(".client_tool").css("display", "inline-block");
    });
    $(".cancel").click(function () {
        $(this).parent(".client_tool").css("display", "none");
    });


    /**************评论信息 列表切换**************/
    $("#discuss_caiwu_bar ul li").click(function () {
        $("#discuss_caiwu_bar ul li").removeClass("caiwu_bar_choice");
        $(this).addClass("caiwu_bar_choice");
        $(".discuss_caiwu_list").hide();
        $(".bottom_page").show();
        $("#" + $(this).attr("data")).show();
    });

    /**************收藏信息 列表切换**************/
    $("#collect_caiwu_bar ul li").click(function () {
        $("#collect_caiwu_bar ul li").removeClass("caiwu_bar_choice");
        $(this).addClass("caiwu_bar_choice");
        $(".collect_caiwu_list").hide();
        $(".bottom_page").show();
        $("#" + $(this).attr("data")).show();
    });


    //获取用户基本信息
    getuserinfo();

    getData();

});

function getData() {

    /*******基本信息***********/
    $("#basic_info").click(function () {
        $(".bottom_page").hide();
        getuserinfo();
    });

    /*******定制游***********/
    $("#tailor_made").click(function () {
        $(".bottom_page").show();
        getUserCustominfo();
        // ttname = "用户定制信息";
        // $("#first_button").click();
    });


    /*******评论信息-默认调用评论农家信息***********/
    $("#discuss").click(function () {
        $(".bottom_page").show();
        var tab = $("#discuss_caiwu_bar ul").find(".caiwu_bar_choice").attr("data");
        if (tab == "discuss_list1") {
            ttname = "评论农家记录";
        } else if (tab == "discuss_list2") {
            ttname = "评论景区记录";
        }
        $("#first_button").click();
    });

    /*******评论信息-调用评论农家信息***********/
    $("#discuss_plnj").click(function () {
        $(".bottom_page").show();
        ttname = "评论农家记录";
        $("#first_button").click();
    });

    /*******评论信息-调用评论景区信息***********/
    $("#discuss_pljq").click(function () {
        $(".bottom_page").show();
        ttname = "评论景区记录";
        $("#first_button").click();
    });

    /*******收藏信息-默认调用收藏农家信息***********/
    $("#collect").click(function () {
        $(".bottom_page").show();
        var tab = $("#collect_caiwu_bar ul").find(".caiwu_bar_choice").attr("data");
        if (tab == "collect_list1") {
            ttname = "收藏农家记录";
        } else if (tab == "collect_list2") {
            ttname = "收藏景区记录";
        }
        $("#first_button").click();
    });

    /*******收藏信息-调用收藏农家信息***********/
    $("#collect_plnj").click(function () {
        $(".bottom_page").show();
        ttname = "收藏农家记录";
        $("#first_button").click();
    });

    /*******收藏信息-调用收藏景区信息***********/
    $("#collect_pljq").click(function () {
        $(".bottom_page").show();
        ttname = "收藏景区记录";
        $("#first_button").click();
    });
}

/****************************---------基本详情------------*********************************/
//数据列表
function getuserinfo() {
    var layLoad = layer.load(2);
    $.post('/getUserOne', {
        "user_encryptId": current_user_encryptId
    }, function (value) {
        layer.close(layLoad);
        if (value.status == 0 && value.msg == "ok") {
            var list = value.list;
            if (list.length > 0) {
                $("#client_name").text(list[0].tel + "客户详情");
                $("#cusername").text((list[0].username == null ? "" : list[0].username));
                $("#csex").attr("value", (list[0].sex == null ? "" : list[0].sex));
                $("#ctel").attr("value", (list[0].tel == null ? "" : list[0].tel));
                $("#crealName").text((list[0].realName == null ? "" : list[0].realName));
                $("#cemail").attr("value", (list[0].user_mail == null ? "" : list[0].user_mail));
                $("#ccreatetime").text((list[0].createtime == null ? "" : list[0].createtime));

                palytypelist = list[0].user_hobby_yw; //游玩类型
                themelist = list[0].user_hobby_zt; //主题游

                getThemelist();
                getSecPlayTypelist();
            }

        } else {
            if (value.msg == null || value.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}


//获取全部的主题游信息列表
function getThemelist() {
    $("#themeRemarks").html("");
    $.post('/SceThemeType/getAllSceThemetype', {}, function (data) {
        if (data.status == 0 && data.msg == 'ok') {
            var list = data.list;
            var str = "";
            var themeRemarkslist = themelist.split(",");
            if (list.length > 0) {
                for (var i = 0; i < list.length; i++) {
                    if ($.inArray(list[i].title, themeRemarkslist) != -1) {
                        str += "<li><a href=\"javascript:void(0)\" onclick='modifyRemarks(this)' name=\"" + list[i].themeId + "\"  value=\"" + list[i].encryptId + "\" class=\"xinjian_btn remarks_a\">" + list[i].title + "</a></li>";
                    } else {
                        str += "<li><a href=\"javascript:void(0)\" onclick='modifyRemarks(this)' name=\"" + list[i].themeId + "\"  value=\"" + list[i].encryptId + "\" class=\"xinjian_btn_white remarks_a\">" + list[i].title + "</a></li>";
                    }
                }
                $("#themeRemarks").html(str);
            }
        } else {
            if (data.msg == null || data.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(data.msg, {icon: 2})
            }
        }
    })

}

//获取景区游玩类型
function getSecPlayTypelist() {
    $("#playRemarks").html("");
    $.post('/ScePlayType/getAllScePlaytype', {}, function (data) {
        if (data.status == 0 && data.msg == 'ok') {
            var list = data.list;
            var str = "";
            var playRemarkslist = palytypelist.split(",");
            if (list.length > 0) {
                for (var i = 0; i < list.length; i++) {
                    if ($.inArray(list[i].title, playRemarkslist) != -1) {
                        str += "<li><a href=\"javascript:void(0)\" onclick='modifyRemarks(this)' name=\"" + list[i].sceplayId + "\"  value=\"" + list[i].encryptId + "\" class=\"xinjian_btn remarks_a\">" + list[i].title + "</a></li>";
                    } else {
                        str += "<li><a href=\"javascript:void(0)\" onclick='modifyRemarks(this)' name=\"" + list[i].sceplayId + "\"  value=\"" + list[i].encryptId + "\" class=\"xinjian_btn_white remarks_a\">" + list[i].title + "</a></li>";
                    }
                }
                $("#playRemarks").html(str);
            }
        } else {
            if (data.msg == null || data.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(data.msg, {icon: 2})
            }
        }
    })
}


//修改基本信息
function userinfo(updatefiled, updateid, type) {
    var updateval = "";
    if (type == 1) {
        //文本框
        updateval = $("#" + updateid + "").val().trim();
    } else if (type == 2) {
        //select选择器
        updateval = $("#" + updateid + " option:selected").attr("value"); //获取选中的项
    }

    var layLoad = layer.load(2);
    $.post('/updateUserinfo', {
        "user_encryptId": current_user_encryptId,
        "updatefiled": updatefiled,
        "updateval": updateval
    }, function (value) {
        layer.close(layLoad);
        if (value.status == 0 && value.msg == "ok") {

            layer.msg("修改成功！", {icon: 1, time: 2000});

        } else {
            if (value.msg == null || value.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}


//修改备注(主题游，游玩类型)
function modifyRemarks(obj) {
    //取消
    if ($(obj).hasClass("xinjian_btn")) {
        $(obj).addClass("xinjian_btn_white").removeClass("xinjian_btn");
    }
    //添加
    else {
        $(obj).addClass("xinjian_btn").removeClass("xinjian_btn_white");
    }

    //主题游备注
    var themeRemarks = "", theme_encryptId = "";
    var ThemeRemarkslist = $(".themeRemarks").find(".xinjian_btn");
    for (var i = 0; i < ThemeRemarkslist.length; i++) {
        if (i == 0) {
            theme_encryptId += $(ThemeRemarkslist[i]).attr('value');
            themeRemarks += $(ThemeRemarkslist[i]).text();
        } else {
            theme_encryptId += "," + $(ThemeRemarkslist[i]).attr('value');
            themeRemarks += "," + $(ThemeRemarkslist[i]).text();
        }
    }

    //游玩类型备注
    var playRemarks = "", play_encryptId = "";
    var playRemarkslist = $(".playRemarks").find(".xinjian_btn");
    for (var i = 0; i < playRemarkslist.length; i++) {
        if (i == 0) {
            play_encryptId += $(playRemarkslist[i]).attr('value');
            playRemarks += $(playRemarkslist[i]).text();
        } else {
            play_encryptId += "," + $(playRemarkslist[i]).attr('value');
            playRemarks += "," + $(playRemarkslist[i]).text();
        }
    }

    //修改
    $.post('/modifyUserRemarks', {
        "user_encryptId": current_user_encryptId,
        "themeRemarks": themeRemarks,
        "playRemarks": playRemarks
    }, function (value) {
        if (value.status == 0 && value.msg == 'ok') {

        } else {
            //取消
            if ($(obj).hasClass("xinjian_btn")) {
                $(obj).addClass("xinjian_btn_white").removeClass("xinjian_btn");
            } else {
                //添加
                $(obj).addClass("xinjian_btn").removeClass("xinjian_btn_white");
            }
            if (value.msg == null || value.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(value.msg, {icon: 2})
            }
        }
    })

}


/*******************************************-----定制游-----****************************************/
var pick_sortfild = '';
var pick_sortway = '';
$(function () {
    //排序
    $(".pick_list_sort_tab").click(function () {
        pick_sortfild = $(this).attr("value");
        if ($(this).find("i").hasClass("icon_downs")) {
            $(this).find("i").removeClass("icon_downs");
            $(this).find("i").addClass("icon_ups");
            pick_sortway = "asc";
        } else {
            $(this).find("i").removeClass("icon_ups");
            $(this).find("i").addClass("icon_downs");
            pick_sortway = "desc";
        }
        //必须要，否则排序则不能调用该方法  使用该句，当点击排序，就同时点击了 第一页的按钮，自动调用分页的效果，
        ttname = "用户定制信息";
        $("#first_button").click();
    })

    //下拉框
    $(document).on('click', ".my_select_ul li", function () {
        $(this).parent().siblings("div").find("span").html($(this).text());
        $(this).parent().siblings("div").find("span").attr("value", $(this).attr("value"));
        if ($(this).parent().siblings("div").find("span").hasClass("type_select")) {
            if ($(this).text() == "全部") {
                $(".type_select").text("挑选类型");
            }
        } else if ($(this).parent().siblings("div").find("span").hasClass("category_select")) {
            if ($(this).text() == "全部") {
                $(".category_select").text("定制类别");
            }
        } else if ($(this).parent().siblings("div").find("span").hasClass("datasource_select")) {
            if ($(this).text() == "全部") {
                $(".datasource_select").text("数据来源");
            }
        } else if ($(this).parent().siblings("div").find("span").hasClass("applicant_select")) {
            if ($(this).text() == "全部") {
                $(".applicant_select").text("申请人");
            }
        }
        //获取数据
        ttname = "用户定制信息";
        $("#first_button").click();
    })
})

//数据记录
function getUserCustominfo() {
    var pagesize = $("#selectPageSize1").text();
    var pageindex = $("#currentPage").text();
    var type = $("#type_select_name").attr("value");//挑选类型
    var category = $("#category_select_name").attr("value");//定制类别
    var datasource = $("#datasource_select_name").attr("value");//数据来源
    var applicant = $("#applicant_select_name").attr("value");//申请人
    var layLoad = layer.load(2);
    $("#my_pick_list").empty();
    $.post('/custom/getcustolist', {
        "pagesize": pagesize,
        "pageindex": pageindex,
        "starttime": starttime,
        "endtime": endtime,
        "searchval": "",
        "searchkey": "",
        "sortfild": pick_sortfild,
        "sortway": pick_sortway,
        "type": type,
        "category": category,
        "datasource": datasource,
        "applicant": "",
        "user_encryptId": current_user_encryptId
    }, function (value) {
        layer.close(layLoad);
        if (value.status == 0 && value.msg == "ok") {
            var list = value.list;
            var applylist = value.applylist;
            var pagecount = value.pagecount;
            var recordcount = value.recordcount;
            $("#totalSize").html(recordcount);
            $("#totalPage").html(pagecount);


            if (list.length == 0) {
                $("#my_pick_list").prepend("<tr class=\"iframe_tr iframe_bg\"><td colspan=\"13\" style=\"width:1126px;text-align:center;\">暂无数据</td></tr>");
            } else {
                var htm = "";
                for (var i = 0; i < list.length; i++) {
                    htm += "<tr>";
                    htm += "<td><span class='show_tips'>" + (list[i].type == null ? "" : gettypeName(list[i].type)) + "</span></td>";
                    // htm+="<td><span class='show_tips'>"+(list[i].applicatName == null ? "" :list[i].applicatName)+"</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].user_name == null ? "" : list[i].user_name) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].user_realName == null ? "" : list[i].user_realName) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].tel == null ? "" : list[i].tel) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].category == null ? "" : getCategoryName(list[i].category)) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].dataSources == null ? "" : getdataSources(list[i].dataSources)) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].CompanyName == null ? "" : list[i].CompanyName) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].createtime == null ? "" : list[i].createtime) + "</span></td>";

                    htm += "<td class='td-manage'>";
                    htm += "<a href=\"javascript:void(0)\" onclick=\"question_Customdetails('" + list[i].user_tel + "','" + list[i].user_id + "','" + list[i].cust_encryptId + "','" + list[i].user_encryptId + "')\">详情</a></div>";
                    htm += "<a href=\"javascript:void(0)\" onclick=\"question_Customdel('" + list[i].cust_encryptId + "')\">删除</a></div>";
                    htm += "</td>";

                    htm += "</tr>";
                }
                $("#my_pick_list").html(htm);

            }
        } else {
            if (value.msg == null || value.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}

//挑选类型
function gettypeName(type) {
    if (type != "") {
        if (type == "1") {
            return "挑选农家"
        } else if (type == "2") {
            return "挑选景区"
        }
        return "";
    }
    return "";
}
//定制类型
function getCategoryName(category) {
    if (category != "") {
        if (category == "1") {
            return "私人定制"
        } else if (category == "2") {
            return "团队定制"
        }
        return "";
    }
    return "";
}
//数据来源
function getdataSources(dataSources) {
    if (dataSources != "") {
        if (dataSources == "0") {
            return "管理系统"
        } else if (dataSources == "1") {
            return "前端官网"
        }
        return "";
    }
    return "";
}

//点击详情 - 跳转商家详情信息页面（应判断用户提交的是挑选农家，还旅游景区）
function question_Customdetails(user_tel, user_id, cust_encryptId, user_encryptId) {
    setcookie("tel", user_tel, 1, "/");//注册时，用户填写的电话号码
    setcookie("user_id", user_id, 1, "/"); //用户id
    setcookie("user_encryptid", user_encryptId, 1, "/"); //用户加密id
    setcookie("cust_encryptid", cust_encryptId, 1, "/"); //定制游加密id
    var size = "pick-farm/pick_info_new.html".length;
    window.parent.addTab_father("定制详情", "pick-farm/pick_info_new.html", size);
}

//删除
function question_Customdel(id) {
    layer.confirm('确认要删除吗？', function (index) {
        var ii = layer.load(2);
        $.post('/custom/delcustom', {"custEncryptid": id}, function (data) {
            layer.close(ii);
            if (data.status == 0 && data.msg == 'ok') {
                layer.msg("操作成功！", {time: 2000, icon: 1});
                ttname = "用户定制信息";
                $("#first_button").click();
            } else {
                if (data.msg == null || data.msg == "") {
                    layer.alert("接口出现错误！", {icon: 2})
                } else {
                    layer.alert(data.msg, {icon: 2})
                }
            }
        })
    });
}


/*******************************************-----评论信息-----****************************************/
//农家排序字段
var discuss_farm_sortfild = '';
var discuss_farm_sortway = '';
//景区排序字段
var discuss_scenic_sortfild = '';
var discuss_scenic_sortway = '';
$(function () {
    //排序
    $(".discus_farm_list_sort_tab").click(function () {
        discuss_farm_sortfild = $(this).attr("value");
        if ($(this).find("i").hasClass("icon_downs")) {
            $(this).find("i").removeClass("icon_downs");
            $(this).find("i").addClass("icon_ups");
            discuss_farm_sortway = "asc";
        } else {
            $(this).find("i").removeClass("icon_ups");
            $(this).find("i").addClass("icon_downs");
            discuss_farm_sortway = "desc";
        }

        ttname = "评论农家记录";
        $("#first_button").click();
    })

    $(".discuss_scenic_list_sort_tab").click(function () {
        discuss_scenic_sortfild = $(this).attr("value");
        if ($(this).find("i").hasClass("icon_downs")) {
            $(this).find("i").removeClass("icon_downs");
            $(this).find("i").addClass("icon_ups");
            discuss_scenic_sortway = "asc";
        } else {
            $(this).find("i").removeClass("icon_ups");
            $(this).find("i").addClass("icon_downs");
            discuss_scenic_sortway = "desc";
        }

        ttname = "评论景区记录";
        $("#first_button").click();
    })

    //下拉框
    $(document).on('click', ".my_select_ul li", function () {
        $(this).parent().siblings("div").find("span").html($(this).text());
        $(this).parent().siblings("div").find("span").attr("value", $(this).attr("value"));
        if ($(this).parent().siblings("div").find("span").hasClass("discuss_tour_select")) {
            if ($(this).text() == "全部") {
                $(".discuss_tour_select").text("景区类型");
            }

            //获取数据
            ttname = "评论景区记录";
            $("#first_button").click();
        } else if ($(this).parent().siblings("div").find("span").hasClass("discuss_farm_select")) {
            if ($(this).text() == "全部") {
                $(".discuss_farm_select").text("农家类型");
            }

            //获取数据
            ttname = "评论农家记录";
            $("#first_button").click();
        }
    })

})

//评论农家记录_数据列表
function getUserDiscussfarminfo() {
    var field = $("#search_name").attr("value"); //搜索字段
    var pagesize = $("#selectPageSize1").text();
    var pageindex = $("#currentPage").text();
    var layLoad = layer.load(2);
    $("#discuss_farm_list").empty();
    $.post('/farmdiscuss/getfarmdiscusslist', {
        "pagesize": pagesize,
        "pageindex": pageindex,
        "starttime": "",
        "endtime": "",
        "searchkey": "",
        "searchval": "",
        "sortfild": discuss_farm_sortfild,
        "sortway": discuss_farm_sortway,
        "farm_encryptId": "",
        "user_encryptId": current_user_encryptId
    }, function (value) {
        layer.close(layLoad);
        if (value.status == 0 && value.msg == "ok") {
            var list = value.list;
            var pagecount = value.pagecount;
            var recordcount = value.recordcount;
            $("#totalSize").html(recordcount);
            $("#totalPage").html(pagecount);
            if (list.length == 0) {
                $("#discuss_farm_list").prepend("<tr class=\"iframe_tr iframe_bg\"><td colspan=\"9\" style=\"width:1126px;text-align:center;\">暂无数据</td></tr>");
            } else {
                var htm = "";
                for (var i = 0; i < list.length; i++) {
                    htm += "<tr>";
                    htm += "<td><span class='show_tips'>" + (list[i].farmTypeName == null ? "" : list[i].farmTypeName) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].CompanyName == null ? "" : list[i].CompanyName) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].username == null ? "" : list[i].username) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].score == null ? "" : list[i].score + "分") + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].context == null ? "" : list[i].context) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].impression == null ? "" : list[i].impression) + "</span></td>";

                    if (list[i].discus_img != "" && list[i].discus_img != null) {
                        htm += "<td><a href='javascript:void(0)' class='show_img' src='" + list[i].discus_img + "'>查看</a></td>";
                    } else {
                        htm += "<td></td>";
                    }
                    htm += "<td><span class='show_tips'>" + list[i].createtime + "</span></td>";

                    htm += "<td class='td-manage'>";
                    htm += "<a class=\"customerdetail\" onclick=\"question_discussdetails('" + list[i].business_encryptId + "','" + list[i].farm_encryptId + "','" + list[i].businessTypeid + "')\">详情</a>";
                    htm += "<a href=\"javascript:void(0)\" onclick=\"question_discussfarmdel('" + list[i].discus_id + "')\">删除</a></div>";
                    htm += "</td>";

                    htm += "</tr>";
                }
                $("#discuss_farm_list").html(htm);
            }
        } else {
            if (value.msg == null || value.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}


/**
 *  农家乐评论——删除
 * @param discus_id  评论id
 */
function question_discussfarmdel(discus_id) {
    if(discus_id != ""){
        layer.confirm('确认要删除吗？', function(index) {
            var ii = layer.load(2);
            $.post('/farmdiscuss/deldiscussfarm', {"discus_id": discus_id}, function (data) {
                layer.close(ii);
                if (data.status == 0 && data.msg == 'ok') {
                    layer.msg("操作成功！",{time:2000,icon:1});
                    getUserDiscussfarminfo();
                    mclose();

                } else {
                    if(data.msg==null||data.msg==""){
                        layer.alert("接口出现错误！", {icon: 2})
                    }else{
                        layer.alert(data.msg, {icon: 2})
                    }
                }
            })
        });
    }else {
        layer.alert("discus_id不能为空！",{icon:2,time:2000});
    }

}



//评论景区记录_数据列表
function getUserDiscussScenicinfo() {
    var pagesize = $("#selectPageSize1").text();
    var pageindex = $("#currentPage").text();
    var layLoad = layer.load(2);
    $("#discuss_scenic_list").empty();
    $.post('/scediscuss/getSceincdiscusslist', {
        "pagesize": pagesize,
        "pageindex": pageindex,
        "starttime": "",
        "endtime": "",
        "searchkey": "",
        "searchval": "",
        "sortfild": discuss_scenic_sortfild,
        "sortway": discuss_scenic_sortway,
        "sceinc_encryptId": "",
        "user_encryptId": current_user_encryptId
    }, function (value) {
        layer.close(layLoad);
        if (value.status == 0 && value.msg == "ok") {
            var list = value.list;
            var pagecount = value.pagecount;
            var recordcount = value.recordcount;
            $("#totalSize").html(recordcount);
            $("#totalPage").html(pagecount);
            if (list.length == 0) {
                $("#discuss_scenic_list").prepend("<tr class=\"iframe_tr iframe_bg\"><td colspan=\"9\" style=\"width:1126px;text-align:center;\">暂无数据</td></tr>");
            } else {
                var htm = "";
                for (var i = 0; i < list.length; i++) {
                    htm += "<tr>";
                    htm += "<td><span class='show_tips'>" + (list[i].scenicTypeName == null ? "" : list[i].scenicTypeName) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].CompanyName == null ? "" : list[i].CompanyName) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].username == null ? "" : list[i].username) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].score == null ? "" : list[i].score + "分") + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].context == null ? "" : list[i].context) + "</span></td>";
                    htm += "<td><span class='show_tips'>" + (list[i].impression == null ? "" : list[i].impression) + "</span></td>";

                    if (list[i].discus_img != "" && list[i].discus_img != null) {
                        htm += "<td><a href='javascript:void(0)' class='show_img' src='" + list[i].discus_img + "'>查看</a></td>";
                    } else {
                        htm += "<td></td>";
                    }
                    // 这一次我依你，以后不再打扰你。以后道路分明
                    htm += "<td><span class='show_tips'>" + list[i].createtime + "</span></td>";

                    htm += "<td class='td-manage'>";
                    htm += "<a class=\"customerdetail\" onclick=\"question_discussdetails('" + list[i].business_encryptId + "','" + list[i].scenic_encryptId + "','" + list[i].businessTypeid + "')\">详情</a>";
                    htm += "<a href=\"javascript:void(0)\" onclick=\"question_discussSceincdel('" + list[i].discus_id + "')\">删除</a></div>";
                    htm += "</td>";

                    htm += "</tr>";
                }
                $("#discuss_scenic_list").html(htm);

            }
        } else {
            if (value.msg == null || value.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}


/**
 *  景区评论——删除
 * @param discus_id  评论id
 */
function question_discussSceincdel(discus_id) {
    if(discus_id != ""){
        layer.confirm('确认要删除吗？', function(index) {
            var ii = layer.load(2);
            $.post('/scediscuss/deldiscussSceinc', {"discus_id": discus_id}, function (data) {
                layer.close(ii);
                if (data.status == 0 && data.msg == 'ok') {
                    layer.msg("操作成功！",{time:2000,icon:1});
                    getUserDiscussScenicinfo();
                    mclose();

                } else {
                    if(data.msg==null||data.msg==""){
                        layer.alert("接口出现错误！", {icon: 2})
                    }else{
                        layer.alert(data.msg, {icon: 2})
                    }
                }
            })
        });
    }else {
        layer.alert("discus_id不能为空！",{icon:2,time:2000});
    }

}


//进入商家详情页
function question_discussdetails(business_encryptId, shop_encryptId, businessTypeid) {
    setcookie("business_encryptId", business_encryptId, 1, "/");//商家加密id
    setcookie("shop_encryptId", shop_encryptId, 1, "/"); //店铺加密id
    if (businessTypeid == "1") {
        var size = "merchant/merchant_information_new.html".length;
        window.parent.addTab_father("农家乐商家详情", "merchant/merchant_information_new.html", size);
    } else if (businessTypeid == "2") {
        var size = "tourist/tour_info_new.html".length;
        window.parent.addTab_father("景区商家详情", "tourist/tour_info_new.html", size);
    }
}



/*******************************************-----收藏信息-----****************************************/
//农家排序字段
var collect_farm_sortfild = '';
var collect_farm_sortway = '';
//景区排序字段
var collect_scenic_sortfild = '';
var collect_scenic_sortway = '';
$(function () {
    //排序
    $(".collect_farm_list_sort_tab").click(function () {
        collect_farm_sortfild = $(this).attr("value");
        if ($(this).find("i").hasClass("icon_downs")) {
            $(this).find("i").removeClass("icon_downs");
            $(this).find("i").addClass("icon_ups");
            collect_farm_sortway = "asc";
        } else {
            $(this).find("i").removeClass("icon_ups");
            $(this).find("i").addClass("icon_downs");
            collect_farm_sortway = "desc";
        }

        ttname = "收藏农家记录";
        $("#first_button").click();
    })

    $(".collect_scenic_list_sort_tab").click(function () {
        collect_scenic_sortfild = $(this).attr("value");
        if ($(this).find("i").hasClass("icon_downs")) {
            $(this).find("i").removeClass("icon_downs");
            $(this).find("i").addClass("icon_ups");
            collect_scenic_sortway = "asc";
        } else {
            $(this).find("i").removeClass("icon_ups");
            $(this).find("i").addClass("icon_downs");
            collect_scenic_sortway = "desc";
        }

        ttname = "收藏景区记录";
        $("#first_button").click();
    })

    //下拉框
    $(document).on('click', ".my_select_ul li", function () {
        $(this).parent().siblings("div").find("span").html($(this).text());
        $(this).parent().siblings("div").find("span").attr("value", $(this).attr("value"));
        if ($(this).parent().siblings("div").find("span").hasClass("collect_tour_select")) {
            if ($(this).text() == "全部") {
                $(".collect_tour_select").text("景区类型");
            }

            //获取数据
            ttname = "收藏景区记录";
            $("#first_button").click();
        } else if ($(this).parent().siblings("div").find("span").hasClass("collect_farm_select")) {
            if ($(this).text() == "全部") {
                $(".collect_farm_select").text("农家类型");
            }

            //获取数据
            ttname = "收藏农家记录";
            $("#first_button").click();
        }

    })

})

//收藏农家记录_数据列表
function getUserCollectfarminfo() {
    var pagesize = $("#selectPageSize1").text();
    var pageindex = $("#currentPage").text();
    var shoptype =  $("#collect_farm_name").attr("value"); //店铺类型
    var layLoad=layer.load(2);
    $("#collect_farm_list").empty();
    $.post('/farmCollect/getfarmcollectlist', {
        "pagesize": pagesize,
        "pageindex": pageindex,
        "starttime": "",
        "endtime": "",
        "searchkey": "",
        "searchval": "",
        "sortfild": collect_farm_sortfild,
        "sortway": collect_farm_sortway,
        "farm_encryptId": "",
        "user_encryptId":current_user_encryptId,
        "shoptype":shoptype
    }, function (value) {
        layer.close(layLoad);
        if(value.status==0 && value.msg == "ok"){
            var list=value.list;
            var pagecount=value.pagecount;
            var recordcount=value.recordcount;
            $("#totalSize").html(recordcount);
            $("#totalPage").html(pagecount);
            if(list.length==0){
                $("#collect_farm_list").prepend("<tr class=\"iframe_tr iframe_bg\"><td colspan=\"5\" style=\"width:1126px;text-align:center;\">暂无数据</td></tr>");
            }else{
                var htm="";
                for(var i=0;i<list.length;i++){
                    htm+="<tr>";
                    htm+="<td><span class='show_tips'>"+(list[i].farmTypeName==null?"":list[i].farmTypeName)+"</span></td>";
                    htm+="<td><span class='show_tips'>"+(list[i].CompanyName == null ? "" :list[i].CompanyName)+"</span></td>";
                    htm+="<td><span class='show_tips'>"+(list[i].username == null ? "" :list[i].username)+"</span></td>";
                    htm+="<td><span class='show_tips'>"+list[i].createtime+"</span></td>";

                    htm += "<td class='td-manage'>";
                    htm += "<a class=\"customerdetail\" onclick=\"question_discussdetails('" + list[i].business_encryptId + "','" + list[i].farm_encryptId + "','" + list[i].businessTypeid + "')\">详情</a>";
                    htm += "<a href=\"javascript:void(0)\" onclick=\"question_collectfarmdel('" + list[i].collect_id + "')\">取消收藏</a></div>";
                    htm += "</td>";

                    htm+="</tr>";
                }
                $("#collect_farm_list").html(htm);

            }
        }else{
            if(value.msg==null||value.msg==""){
                layer.alert("接口出现错误！", {icon: 2})
            }else{
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}

//农家乐——取消收藏
function question_collectfarmdel(collect_id) {
    if(collect_id != ""){
        layer.confirm('确认要删除吗？', function(index) {
            var ii = layer.load(2);
            $.post('/farmCollect/delCollectfarm', {"collect_id": collect_id}, function (data) {
                layer.close(ii);
                if (data.status == 0 && data.msg == 'ok') {
                    layer.msg("操作成功！",{time:2000,icon:1});
                    getUserCollectfarminfo();
                    mclose();

                } else {
                    if(data.msg==null||data.msg==""){
                        layer.alert("接口出现错误！", {icon: 2})
                    }else{
                        layer.alert(data.msg, {icon: 2})
                    }
                }
            })
        });
    }else {
        layer.alert("collect_id不能为空！",{icon:2,time:2000});
    }

}


//收藏景区记录_数据列表
function getUserCollectScenicinfo() {
    var field=$("#search_name").attr("value"); //搜索字段
    var pagesize = $("#selectPageSize1").text();
    var pageindex = $("#currentPage").text();
    var layLoad=layer.load(2);
    $("#collect_scenic_list").empty();
    $.post('/scecollect/getSceinccollectlist', {
        "pagesize": pagesize,
        "pageindex": pageindex,
        "starttime": "",
        "endtime": "",
        "searchkey": "",
        "searchval": "",
        "sortfild": collect_scenic_sortfild,
        "sortway": collect_scenic_sortway,
        "sceinc_encryptId": "",
        "user_encryptId":current_user_encryptId

    }, function (value) {
        layer.close(layLoad);
        if(value.status==0 && value.msg == "ok"){
            var list=value.list;
            var pagecount=value.pagecount;
            var recordcount=value.recordcount;
            $("#totalSize").html(recordcount);
            $("#totalPage").html(pagecount);
            if(list.length==0){
                $("#collect_scenic_list").prepend("<tr class=\"iframe_tr iframe_bg\"><td colspan=\"5\" style=\"width:1126px;text-align:center;\">暂无数据</td></tr>");
            }else{
                var htm="";
                for(var i=0;i<list.length;i++){
                    htm+="<tr>";
                    htm+="<td><span class='show_tips'>"+(list[i].scceincTypeName==null?"":list[i].scceincTypeName)+"</span></td>";
                    htm+="<td><span class='show_tips'>"+(list[i].CompanyName == null ? "" :list[i].CompanyName)+"</span></td>";
                    htm+="<td><span class='show_tips'>"+(list[i].username == null ? "" :list[i].username)+"</span></td>";
                    htm+="<td><span class='show_tips'>"+list[i].createtime+"</span></td>";

                    htm += "<td class='td-manage'>";
                    htm += "<a class=\"customerdetail\" onclick=\"question_discussdetails('" + list[i].business_encryptId + "','" + list[i].scenic_encryptId + "','" + list[i].businessTypeid + "')\">详情</a>";
                    htm += "<a href=\"javascript:void(0)\" onclick=\"question_collectSceincdel('" + list[i].collect_id + "')\">取消收藏</a></div>";
                    htm += "</td>";

                    htm+="</tr>";
                }
                $("#collect_scenic_list").html(htm);

            }
        }else{
            if(value.msg==null||value.msg==""){
                layer.alert("接口出现错误！", {icon: 2})
            }else{
                layer.alert(value.msg, {icon: 2})
            }
        }
    })
}


//农家乐——取消收藏
function question_collectSceincdel(collect_id) {
    if(collect_id != ""){
        layer.confirm('确认要删除吗？', function(index) {
            var ii = layer.load(2);
            $.post('/scecollect/delCollectSceinc', {"collect_id": collect_id}, function (data) {
                layer.close(ii);
                if (data.status == 0 && data.msg == 'ok') {
                    layer.msg("操作成功！",{time:2000,icon:1});
                    getUserCollectScenicinfo();
                    mclose();

                } else {
                    if(data.msg==null||data.msg==""){
                        layer.alert("接口出现错误！", {icon: 2})
                    }else{
                        layer.alert(data.msg, {icon: 2})
                    }
                }
            })
        });
    }else {
        layer.alert("collect_id不能为空！",{icon:2,time:2000});
    }

}



/***************************************----公共js----******************************************/
//获取农家乐商户类型
function getAllfarmMertype() {
    $(".farm_Mertype").html("");
    $.post('/farmMerType/getAllfarmMertype', {}, function (data) {
        if (data.status == 0 && data.msg == 'ok') {
            var list = data.list;
            var str = "";
            if (list.length > 0) {
                for (var i = 0; i < list.length; i++) {
                    str += "<li encryptId='" + list[i].encryptId + "' value='" + list[i].title + "'><a href='javascript:void(0);'><span class='show_tips'> " + list[i].title + "</span></a></li>";
                }
                if (str != "") {
                    str = "<li encryptId='' value=''><a href='javascript:void(0);'><span class='show_tips'>全部</span></a></li>" + str;
                }
                //页面中
                $(".farm_Mertype").html(str);
            }
        } else {
            if (data.msg == null || data.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(data.msg, {icon: 2})
            }
        }
    })
}

//获取景区商户类型
function getAllSerMertype() {
    $(".tour_type_ul").html("");
    $.post('/SceMerType/getAllSerMertype', {}, function (data) {
        if (data.status == 0 && data.msg == 'ok') {
            var list = data.list;
            var str = "";
            if (list.length > 0) {
                for (var i = 0; i < list.length; i++) {
                    str += "<li encryptId='" + list[i].encryptId + "' value='" + list[i].title + "'><a href='javascript:void(0);'><span class='show_tips'> " + list[i].title + "</span></a></li>";
                }
                if (str != "") {
                    str = "<li encryptId='' value=''><a href='javascript:void(0);'><span class='show_tips'>全部</span></a></li>" + str;
                }
                $(".tour_type_ul").html(str);
            }
        } else {
            if (data.msg == null || data.msg == "") {
                layer.alert("接口出现错误！", {icon: 2})
            } else {
                layer.alert(data.msg, {icon: 2})
            }
        }
    })
}


//图片全屏显示
function enlargeCoatchAttachment(url, currentURL) {
    var url = url.split(",");
    var photos = new Array();
    for (var i = 0; i < url.length; i++) {
        photos.push({"alt": "图片" + (1 + i), "pid": "", "src": url[i], "thumb": ""});
    }
    var json = {"title": "附件图片", "id": "", "start": url.indexOf(currentURL), "data": photos};
    layer.photos({
        photos: json
        , anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        maxHeight: "80%",
        maxWidth: "80%",
        full: true
    });
}
